/*
 * @Author: wangchao
 * @Date: 2025-06-05 11:56:27
 * @LastEditors: wangchao
 * @LastEditTime: 2025-06-05 12:51:04
 * @FilePath: \UX6_ATE-RDO\applications\u_port.c
 * @Description:
 * Copyright (c) 2025 by Bingshan Guardian, All Rights Reserved.
 */

#include "u_port.h"

rt_base_t DO_PINS[] = {DO1, DO2, DO3, DO4, DO5, DO6, DO7, DO8, DO9, DO16, DO15, DO14, DO13, DO10, DO11, DO12};

volatile rt_uint16_t PINS_WORD = 0x0000;  // 16 bits for 16 DO pins

void u_port_init(void)
{
    for (int i = 0; i < sizeof(DO_PINS) / sizeof(DO_PINS[0]); i++)
    {
        rt_pin_mode(DO_PINS[i], PIN_MODE_OUTPUT);
        rt_pin_write(DO_PINS[i], PIN_LOW);
    }

    LOG_I("Port Init Done.");
}

void u_port_set_pin(rt_base_t pin, rt_ssize_t value)
{
    if (pin < 0 || pin >= sizeof(DO_PINS) / sizeof(DO_PINS[0]))
    {
        LOG_E("Invalid pin number: %d", pin);
        return;
    }

    rt_pin_write(DO_PINS[pin], value);
}